﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using ProgramDioptase.Interfaces;
using ProgramDioptase.ItemTypes;

namespace ProgramDioptase
{
    /// <summary>
    /// Interaction logic for InformationAboutCatalogItem.xaml
    /// </summary>
    public partial class InformationAboutCatalogItem : Window
    {
        public InformationAboutCatalogItem()
        {
            this.InitializeComponent();
        }

        public InformationAboutCatalogItem(CatalogItem catalogItem, Uri path)
            : this()
        {
            ElementRenderer.VisualizeImageInPanel(this.ItemInfoPanel, catalogItem, path);

            this.NameText.Text = catalogItem.Name;
            this.GenreText.Text = string.Join(", ", catalogItem.Genres);
            this.YearText.Text = catalogItem.ReleaseYear;

            bool isInStock = (catalogItem as IStockable).IsInStock;
            this.IsInStockText.Text = isInStock ? "Available" : "Not Available";   
            this.IsInStockText.Foreground = isInStock ? Brushes.Green : Brushes.Red;

            if (catalogItem is ISaleable)
            {
                this.SellButton.Visibility = Visibility.Visible;
            }
            else if (catalogItem is IRentable)
            {
                this.RentButton.Visibility = Visibility.Visible;
            }

            this.CloseButton.Focus();
        }

        #region [WINDOW events - Close / Minimize / Moving / Closing / VisibleChanged]

        private void MoveTheWindow(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            SystemCommands.CloseWindow(this);
        }
        
        #endregion  
    }
}